package com.youmingxing.bean;

import org.json.JSONObject;

/**
 * 个人信息
 *
 * @author evilyin(ChenZhixi)
 * @since 15/10/12
 */
public class User {

    public enum Info {
        headimg("头像"),
        nickname("艺名"),
        motto("宣言"),
        gender("性别"),
        birthday("生日"),
        body("身材"),
        career_or_college("职业/学校"),
        address("现居住地"),
        hometown("家乡"),
        link_mobile("联系手机"),
        link_email("联系邮箱"),
        background_img("背景图片");

        private String desc;

        Info(String desc) {
            this.desc = desc;
        }

        public String getDesc() {
            return this.desc;
        }
    }

    /*
       其他属性,用户不能修改
     */
    public int id; //id
    public boolean myfollow; //是否是我关注的人
    public int popularity; //当前人气值
    public float popularityRatio;//人气值相对最大人气值的比例
    public String shapeInfo;
    public int fans_num; //粉丝数量
    public int update_count; //作品数量
    public int height;
    public int weight;
    public String bwh;
    public boolean real_auth; //是否通过实名认证
    public String user_type; //10表示普通用户  11表示官方认证用户

    private String[] userData = new String[Info.values().length];


    public User(JSONObject data) {
        userData[Info.headimg.ordinal()] = data.optString("headimg");
        userData[Info.nickname.ordinal()] = data.optString("nickname");
        userData[Info.motto.ordinal()] = data.optString("motto");
        userData[Info.gender.ordinal()] = setGender(data.optInt("gender"));
        userData[Info.birthday.ordinal()] = data.optString("birthday");
        height = data.optInt("height");
        weight = data.optInt("weight");
        bwh = data.optString("bwh");
        userData[Info.body.ordinal()] = setBody(height, weight, bwh);
        shapeInfo = setShapeInfo(height, weight, bwh);
        userData[Info.career_or_college.ordinal()] = data.optString("career_or_college");
        userData[Info.address.ordinal()] = data.optString("address");
        userData[Info.hometown.ordinal()] = data.optString("hometown");
        userData[Info.link_mobile.ordinal()] = data.optString("link_mobile");
        userData[Info.link_email.ordinal()] = data.optString("link_email");
        userData[Info.background_img.ordinal()] = data.optString("background_img", "");
        myfollow = data.optBoolean("myfollow");
        id = data.optInt("id");
        popularity = data.optInt("popularity");
        int max = data.optInt("popularity_total");
        if (max > 0) {
            popularityRatio = (float) popularity / (float) max;
        }
        update_count = data.optInt("update_count");
        fans_num = data.optInt("fan_count");
        user_type = data.optString("user_type");
        real_auth = data.optBoolean("real_auth");
    }

    public String setGender(int gender) {
        switch (gender) {
            case 1:
                return "男";
            case 2:
                return "女";
            default:
                return "未知";
        }
    }

    public String setBody(int height, int weight, String bwh) {
        return " " + height + "cm " + weight + "kg " + bwh;
    }

    //身高 --cm/体重 -- kg/ 三围 -- -- -- /
    public String setShapeInfo(int height, int weight, String bwh) {
        String heightStr = height == 0 ? " -- " : " " + height + " ";
        String weightStr = weight == 0 ? " -- " : " " + weight + " ";
        String bwhStr;
        if (bwh.equals("") || bwh.equals("0,0,0")) {
            bwhStr = " -- ";
        } else {
            bwhStr = " " + bwh + " ";
        }

        return "身高" + heightStr + "cm " + "/ 体重" + weightStr + "kg " + "/ 三围" + bwhStr;
    }

    public String[] getUserData() {
        return userData;
    }
}
